package org.hxyjs.controller;

import org.hxyjs.dto.DTO;
import org.hxyjs.entity.ExpertActivityRecord;
import org.hxyjs.page.PageInfo;
import org.hxyjs.service.ExpertActivityRecordService;
import org.springframework.cloud.openfeign.SpringQueryMap;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@CrossOrigin
@Controller //@Controller注解是用spring容器生成 对象 默认对象名 expertActivityRecordController
//@RequestMapping("/expertActivityRecordController") //@RequestMapping 用户请求查找该资源使用的名字 网名 默认  /expertActivityRecordController
public class ExpertActivityRecordController {
	@Resource
    ExpertActivityRecordService expertActivityRecordService;

	@GetMapping("/getAllexpertActivityRecord")
	@ResponseBody //把方法的返回值按json转换之后 输出到浏览器
    public DTO<ExpertActivityRecord> getAllExpertActivityRecord() throws Exception{
    	System.out.println("查询全部专家参加活动记录");
    	return expertActivityRecordService.getAllExpertActivityRecords();
    }

	@PostMapping("/addexpertActivityRecord")
	@ResponseBody
	public DTO<ExpertActivityRecord> addExpertActivityRecord(@RequestBody ExpertActivityRecord expertActivityRecord) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("增加专家参加活动记录成功");
		return expertActivityRecordService.addExpertActivityRecord(expertActivityRecord);
	}
	@DeleteMapping("/deleteexpertActivityRecord/{exarno}")
	@ResponseBody
    public DTO<ExpertActivityRecord> deleteExpertActivityRecordByExarno(@RequestBody @PathVariable("exarno") String exarno) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
    	System.out.println(exarno+"删除专家参加活动记录成功");
    	return expertActivityRecordService.deleteExpertActivityRecordByExarno(exarno);
    }

	@GetMapping("/expertActivityRecordBy/{exarno}")
	@ResponseBody
	public DTO<ExpertActivityRecord> getExpertActivityRecordByExarno(@PathVariable("exarno") String exarno) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println(exarno+"根据主键查询专家参加活动记录成功");
		return expertActivityRecordService.getExpertActivityRecordByExarno(exarno);
	}

	@PatchMapping("/updateexpertActivityRecord")
	@ResponseBody
	public DTO<ExpertActivityRecord> updateExpertActivityRecordByExarno(@RequestBody ExpertActivityRecord expertActivityRecord) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("修改专家参加活动记录成功");
		System.out.println(expertActivityRecord);
		return expertActivityRecordService.updateExpertActivityRecordByExarno(expertActivityRecord);
	}

	@RequestMapping("/expertActivityRecord/pageInfo")
	@ResponseBody
	public DTO<ExpertActivityRecord> getExpertActivityRecordByPage(@SpringQueryMap PageInfo pageInfo) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("查询分页");
		return expertActivityRecordService.getExpertActivityRecordByPage(pageInfo);
	}

}
